﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.MonthCalendar;


namespace _3_1
{using System;
using System.Windows.Forms;

    public partial class Form1 : Form
    {
        private Circle circle = new Circle();

        public Form1()
        {
            InitializeComponent();
            this.Text = "Circle类";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double x = Convert.ToDouble(textBox1.Text);
                double y = Convert.ToDouble(textBox2.Text);
                double r = Convert.ToDouble(textBox3.Text);

                circle.SetValue(x, y, r);

                textBox4.Text = circle.GetArea().ToString();
                textBox5.Text = circle.GetPerimeter().ToString();
                textBox6.Text = circle.GetDistance().ToString();
            }
            catch (FormatException)
            {
                MessageBox.Show("请输入有效的数值！");
            }
            catch (Exception ex)
            {
                MessageBox.Show("出错：" + ex.Message);
            }
        }
    }
}


namespace _3_1
{
    public class Circle
    {
        // 这里是Circle类的成员和方法定义
        private double x, y, r;
        private const double PI = Math.PI;

        public void SetValue(double x, double y, double r)
        {
            this.x = x;
            this.y = y;
            this.r = r;
        }

        public double GetArea()
        {
            return Math.Round(PI * r * r, 2);
        }

        public double GetPerimeter()
        {
            return Math.Round(2 * PI * r, 2);
        }

        public double GetDistance()
        {
            return Math.Round(Math.Sqrt(x * x + y * y), 2);
        }
    }
}